package com.herohua.ad.advice;

import com.herohua.ad.exception.AdException;
import com.herohua.ad.vo.CommonResponse;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 */
@RestControllerAdvice
public class GlobalExceptionAdvice {

    /**
     * 拦截AdException异常
     */
    @ExceptionHandler(value = AdException.class)
    public CommonResponse<String> handleAdException(HttpRequest request, AdException e) {

        CommonResponse<String> response = new CommonResponse<>(-1, "Business Error");
        response.setData(e.getMessage());
        return response;
    }
}
